package com.yfp.operation.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.common.log.annotation.Log;
import com.yfp.common.log.enums.BusinessType;
import com.yfp.operation.domain.*;
import com.yfp.operation.domain.dto.*;
import com.yfp.operation.domain.vo.EnterpriseOrderVO;
import com.yfp.operation.service.ThrowPlanService;
import com.yfp.operation.domain.CPComboRoad;
import com.yfp.operation.domain.ComboPlan;
import com.yfp.operation.domain.ComboPlanDevice;
import com.yfp.operation.domain.PlacementPlan;
import com.yfp.operation.domain.dto.*;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *
 * @version 1.0
 * @date 2024-06-26 12:15
 */
@RestController
@RequestMapping
@Tag(name = "投放管理-pc")
@Slf4j
public class ThrowPlanController extends BaseController {

    @Resource
    private ThrowPlanService throwPlanService;


    /**
     * 获取计划组列表
     * @param gainPlacementPlanDTO
     * @return
     */
    @PostMapping(value = "/placement_plan/search")
    @Operation(summary = "获取计划组列表")
    public R<List<PlacementPlan>> getAllPlan(@RequestBody GainPlacementPlanDTO gainPlacementPlanDTO){
        log.info("gainPlacementPlanDTO:{}", gainPlacementPlanDTO);
        return throwPlanService.getAllPlan(gainPlacementPlanDTO);
    }

    /**
     * 新增计划组
     * @param insertPlacementPlanDTO
     * @return
     */
    @PostMapping("/placement_plan")
    @Operation(summary = "新增计划组")
    public R<Void> addPlan(@RequestBody InsertPlacementPlanDTO insertPlacementPlanDTO) {
        return throwPlanService.addPlan(insertPlacementPlanDTO);
    }


    /**
     * 修改计划组
     * @param updatePlacementPlanDTO
     * @return
     */
    @PutMapping("/placement_plan")
    @Log(title = "修改计划组", businessType = BusinessType.UPDATE)
    @Operation(summary = "修改计划组")
    public R<Void> updatePlan(@RequestBody UpdatePlacementPlanDTO updatePlacementPlanDTO) {
        return throwPlanService.updatePlan(updatePlacementPlanDTO);
    }


    /**
     * 删除计划组
     * @param placementPlan
     * @return
     */
    @DeleteMapping("/placement_plan")
    @Log(title = "删除计划组", businessType = BusinessType.DELETE)
    @Operation(summary = "删除计划组")
    public R<Void> deleteByPlanId(@ApiParam(value = "计划组id") @NotNull(message = "计划组id不能为空") @RequestBody PlacementPlan placementPlan) {
        return throwPlanService.deleteByPlanId(placementPlan);
    }


    /**
     * 获取投放餐品计划列表
     * @param gainComboPlanDTO
     * @return
     */
    @GetMapping("/placement_plan/combo_plan/search")
    @Operation(summary = "获取投放餐品计划列表")
    public R<TableDataInfo<List<ComboPlan>>> getAllComboPlan(GainComboPlanDTO gainComboPlanDTO){
        startPage();
        log.info("GainComboPlanDTO：{}", gainComboPlanDTO);
        List<ComboPlan> allComboPlan = throwPlanService.getAllComboPlan(gainComboPlanDTO);
        return R.ok(getDataTable(allComboPlan));
    }


    /**
     * 新增套餐投放计划
     * @param comboPlanDTO
     * @return
     */
    @PostMapping("/placement_plan/combo_plan")
    @Operation(summary = "新增套餐投放计划")
    public R<Void> addComboPlan(@RequestBody ComboPlanDTO comboPlanDTO) {
        return throwPlanService.addComboPlan(comboPlanDTO);
    }


    /**
     * 修改套餐投放计划
     * @param comboPlanDTO
     * @return
     */
    @PutMapping("/placement_plan/combo_plan")
    @Log(title = "修改套餐投放计划", businessType = BusinessType.UPDATE)
    @Operation(summary = "修改套餐投放计划")
    public R<Void> updateComboPlan(@RequestBody ComboPlanDTO comboPlanDTO) {
        return throwPlanService.updateComboPlan(comboPlanDTO);
    }


    @PostMapping("/auto/enterprise/placementPlan")
    @Operation(summary = "根据企业订单生成投放计划")
    public R<Void> autoEnterprisePlacementPlan(@RequestBody EnterpriseOrderVO enterpriseOrderVO) {
        throwPlanService.autoEnterprisePlacementPlan(enterpriseOrderVO);
        return R.ok();
    }

    @DeleteMapping("/del/enterprise/placementPlan")
    @Log(title = "删除企业订单生成投放计划", businessType = BusinessType.DELETE)
    @Operation(summary = "删除企业订单生成投放计划")
    public R<Void> delEnterprisePlacementPlan(String machineId) {
        throwPlanService.delEnterprisePlacementPlan(machineId);
        return R.ok();
    }

    /**
     * 修改状态
     * @param cPlanId
     * @param status
     * @return
     */
    @PutMapping("/placement_plan/combo_plan/status")
    @Log(title = "投放计划修改状态", businessType = BusinessType.UPDATE)
    @Operation(summary = "修改状态")
    public R<Void> updateStatus(@ApiParam(value = "套餐计划id") @NotNull(message = "套餐计划id不能为空")String cPlanId,
                                             @ApiParam(value = "状态") @NotNull(message = "状态不能为空")String status)
    {
        return throwPlanService.updateStatus(cPlanId,status);
    }


    /**
     * 根据餐品计划id获取设备信息
     * @param cPlanId
     * @return
     */
    @GetMapping("/placement_plan/combo_plan/device/by_c_plan_id")
    @Operation(summary = "根据餐品计划id获取设备信息")
    public R<List<ComboPlanDevice>> getByMachineName(@RequestParam("c_plan_id") @ApiParam(value = "套餐计划id") @NotNull(message = "套餐计划id不能为空") String cPlanId) {
        return throwPlanService.getByMachineName(cPlanId);
    }


    /**
     * 根据餐品计划id获取货道餐品信息
     * @param cPlanId
     * @return
     */
    @GetMapping("/placement_plan/combo_plan/road/by_c_plan_id")
    @Operation(summary = "根据餐品计划id获取货道餐品信息")
    public R<List<CPComboRoad>> getComboName(@RequestParam("c_plan_id") @ApiParam(value = "套餐计划id") @NotNull(message = "套餐计划id不能为空") String cPlanId) {
        return throwPlanService.getComboName(cPlanId);
    }


    /**
     * 投放餐品计划选择商品下架
     * @param comboSoldOutDTO
     * @return
     */
    @PutMapping("/placement_plan/combo_plan/road/combo/ban")
    @Operation(summary = "投放餐品计划选择商品下架")
    public R<Void> comboSoldOut(@RequestBody ComboSoldOutDTO comboSoldOutDTO) {
        return throwPlanService.comboSoldOut(comboSoldOutDTO);
    }


    /**
     * 定时修改计划组为结束状态
     * @return
     */
    @PutMapping("/placement_plan/plan/status")
    @Operation(summary = "计划组修改成结束状态")
    R<Void> updatePlanStatus() {
        return throwPlanService.updatePlanStatus();
    }


    /**
     * 定时修改套餐计划为结束状态
     * @return
     */
    @PutMapping("/placement_plan/combo_plan/timing")
    @Operation(summary = "计划组修改成结束状态")
    R<Void> updateComboPlanStatus() {
        return throwPlanService.updateComboPlanStatus();
    }

}
